﻿#region Usings

using System;
using System.Runtime.Serialization;
using System.Security.Principal;
using System.Web.Security;
using XPressify.Data;

#endregion

namespace XPressify.Models
{
    [Serializable]
    public class UserIdentity : MarshalByRefObject, IIdentity 
    {
        private readonly FormsAuthenticationTicket _ticket;


        public UserIdentity(FormsAuthenticationTicket ticket)
        {
            _ticket = ticket;
        }

        public User User
        {
            get { return User.CreateFromTicket(_ticket); }
        }

        public string FriendlyName
        {
            get { return User.FullName; }
        }

        public string[] Roles
        {
            get { return new[] {User.Role}; }
        }

        #region IIdentity Members

        public string Name
        {
            get { return _ticket.Name; }
        }

        public string AuthenticationType
        {
            get { return "Forms"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        #endregion
    }
}